package com.mz.ozy.mvp.presenter;


import android.app.Activity;


import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.NewTbBean;
import com.mz.ozy.bean.TbInfoBean;
import com.mz.ozy.mvp.model.TCoinsModel;
import com.mz.ozy.mvp.view.TCoinsContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class TCoinsPresenter extends BasePresenterImpl<TCoinsContract.View> implements TCoinsContract.Presenter {

    private TCoinsModel mModel;

    public TCoinsPresenter() {
        mModel = new TCoinsModel();
    }


    @Override
    public void getCode(Activity activity,String phone) {
        mModel.getCode(activity,phone)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.getCodeSuccess(jsonObject);
                    }

                });
    }

    @Override
    public void getTbInfo(Activity activity) {
        mModel.getTbInfo(activity)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<TbInfoBean>(mView) {
                    @Override
                    public void onSuccesss(TbInfoBean bean) {
                        mView.getTbInfoSuccess(bean);
                    }

                });
    }


    @Override
    public void onTb(Activity activity, String coinCode, String address, String coinNum, String code) {
        mModel.onTb(activity, coinCode,  address, coinNum, code)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onTbSuccess(jsonObject);
                    }

                });
    }

    @Override
    public void newOnTb(Activity activity, String amount, String name, String account, String type, String padPwd) {
        mModel.newOnTb(activity, amount,  name, account, type, padPwd)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<NewTbBean>(mView) {
                    @Override
                    public void onSuccesss(NewTbBean jsonObject) {
                        mView.newOnTbSuccess(jsonObject);
                    }

                });
    }
}
